<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xh<!-tml1-transitional.dtd">
<%@page import="bridge.*"%>
<%@page import="java.net.URLEncoder"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add Sensor Type</title>
<link rel="stylesheet" type="text/css" href="../style.css" media="screen" />
</head>
<body>
<div id="header">
	<div id="logo">
		<h1>Bridge Viz</h1>
	</div>
	<!-- end #logo -->
	<div id="menu">
		<ul>
			<li><a href="project.jsp">The Project</a></li>
			<li><a href="sensors.jsp">Sensor Info</a></li>
			<li><a href="visualization.jsp">Data Visualization</a></li>
			<li><a href="records.jsp">Records</a></li>
			<li><a href="about.jsp">About Us</a></li>
			<li class="active"><a href="#">Administration</a></li>
		</ul>
	</div>
	<!-- end #menu -->
</div>
<!-- end #header -->
<div id="page">
	<div id="content">
		<div class="post">
			<h2 class="title">Add New Sensor Type</h2>
			<div class="entry">
				<%
					String new_type = request.getParameter("newtype");
					String min = request.getParameter("min");
					String max = request.getParameter("max");
					String unit = request.getParameter("unit");
					String refresh = request.getParameter("refresh");
					String window = request.getParameter("window");
					
					DatabaseAccessor db = DatabaseAccessor.getInstance();
					
					if(new_type != null && min != null && max != null && unit != null)
					{
						SensorType[] types = null;
						types = db.getSensorTypes();
						for(int k = 0; k < types.length; k++)
						{
							if(types[k].type.equals(new_type))
							{
								out.println("<p>Cannot add sensor type; " + new_type + " already exists.</p>");
								new_type = "";
								break;
							}
							else if(k == types.length - 1)
							{
								out.println("<!--" + db.addSensorType(new_type, unit, min, max, refresh, window).replace("\n", "<br>") + "-->");
								out.println("<p>Successfully added sensor type " + new_type + ".</p>");
								new_type = "";
								min = "";
								max = "";
								unit = "";
								refresh= "";
								window = "";
							}
						}

					}
					else
					{
						new_type = "";
						min = "";
						max = "";
						unit = "";
						refresh= "";
						window = "";
					}
				%>
				<table>
				<tr><td>Type</td><td>Unit</td><td>Min</td><td>Max</td><td>Refresh (ms)</td><td>Window (ms)</td></tr>
				<form action="addsensortypes.jsp" method="get"><tr><%="<td><input maxlength='16' size='16' type='text' name='newtype' value='" + new_type + "'></td><td><input maxlength='16' size='8' type='text' name='unit' value='" + unit + "'></td><td><input maxlength='10' size='5' type='text' name='min' value='" + min + "'></td><td><input maxlength='10' size='5' type='text' name='max' value='" + max + "'></td><td><input maxlength='10' size='5' type='text' name='refresh' value='" + refresh + "'></td><td><input maxlength='10' size='5' type='text' name='window' value='" + window + "'></td>"%><td align='right'><input type="submit" value ="Add"></td></tr>
				</form>
				</table>
			</div>
		</div>
	</div>
	<!-- end #content -->
	<div id="sidebar">
		<div id="sidebar-content">
			<ul>
				<li>
					<h2>Sensors</h2>
					<ul>
						<li><a href="modifysensors.jsp">View/Modify Sensors</a></li>
						<li><a href="addsensors.jsp">Add Sensor</a></li>
					</ul>
				</li>
				<li>
					<h2>Sensor Types</h2>
					<ul>
						<li><a href="modifysensortypes.jsp">View/Modify Sensor Types</a></li>
						<li><a href="addsensortypes.jsp">Add Sensor Type</a></li>
					</ul>
				</li>
				<li>
					<h2>Database</h2>
					<ul>
						<li><a href="builddb.jsp">Build Database</a></li>
					</ul>
				</li>
			</ul>
		</div>
	</div>
<!-- end #page -->
<div id="footer">
	<p>&copy; 2008. All Rights Reserved. Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
</div>
<!-- end #footer -->
</body>
</html>
